package primetest.impl.service;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;


import javax.inject.Inject;

import primetest.dto.DoctorDto;
import primetest.impl.dao.DoctorDao;
import primetest.impl.dao.Transaction;
import primetest.impl.service.DoctorService;

public class DoctorService implements  Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 6618357296233537217L;
	private Transaction transaction;
	private DoctorDao doctorDao;

	@Inject
	public DoctorService(Transaction transaction, DoctorDao s_userDao){
		this.transaction =  transaction;
		this.doctorDao = s_userDao;
	}

	
	public DoctorDto findDoctorById(String id) throws IOException {
		try{
			transaction.begin();
			DoctorDto doctorDto = doctorDao.findDoctor(transaction, id);
			//transaction.commit();
			return doctorDto;
		}catch (IOException e){
			transaction.rollback();
			throw e;
		}
	}

	
	public DoctorDto findDoctorBySeq(int seq) throws IOException {
		try{
			transaction.begin();
			DoctorDto doctorDto = doctorDao.findDoctor(transaction, seq);
			//transaction.commit();
			return doctorDto;
		}catch (IOException e){
			transaction.rollback();
			throw e;
		}
	}

	
	public List<DoctorDto> getDoctorListByDepartment(int officeSeq) throws IOException{
		try{
			transaction.begin();
			List<DoctorDto> userList = doctorDao.getDoctorListByDepartment(transaction, officeSeq);
			//transaction.commit();
			return userList;
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}

	
	public void addDoctor(DoctorDto doctorDto) throws IOException {
		try{
			transaction.begin();
			doctorDao.addDoctor(transaction, doctorDto);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}



	
	public void updateDoctor(DoctorDto doctorDto) throws IOException {
		try{
			transaction.begin();
			doctorDao.updateDoctor(transaction, doctorDto);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}



	
	public void deleteDoctor(String id) throws IOException {
		try{
			transaction.begin();
			doctorDao.deleteDoctor(transaction, id);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}

	
	public List<DoctorDto> getDoctorList() throws IOException {
		try{
			transaction.begin();
			List<DoctorDto> userList = doctorDao.getDoctorList(transaction);
			//transaction.commit();
			return userList;
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}

}
